import axios from 'axios';
import qs from 'qs';

export async function getAccessToken() {
  const param = qs.stringify({
    grant_type: 'client_credentials',
    client_id: 'TpxwHwTH48eaSjnrI81sldE7',
    client_secret: 'A0dhaCKr1k3MXxeTWB2ku0l0UmOBAAEB',
  });
  const { data }  = await axios.post('https://aip.baidubce.com/oauth/2.0/token', param);
  return data;
}

export async function getGesture(access_token: string, image: string) {
  const { data } = await axios({
    method: 'post',
    url: `https://aip.baidubce.com/rest/2.0/image-classify/v1/gesture?access_token=${access_token}`,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: qs.stringify({ image }),
  });
  return data;
}
